import re

EXTRA_UNDERLINES_REGEX = re.compile(r"[_]{2,}")
EXTRA_DASHES_REGEX = re.compile(r"[-]{2,}")
EXTRA_DOTS_REGEX = re.compile(r"[.]{2,}")

def normalize_string(text):
    text = text.strip().lower()
    res = []
    for l in text:
        if l == " ":
            res.append('_')
            continue
        if l in ['-', '_', '.']:
            res.append(l)
            continue
        if not l.isalnum():
            continue
        res.append(l)
    str = u"".join(res)
    str = EXTRA_UNDERLINES_REGEX.sub(u'_', str)
    str = EXTRA_DASHES_REGEX.sub(u'-', str)
    str = EXTRA_DOTS_REGEX.sub(u'.', str)
    return str